Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Exceptions.kt 3c7e1266f819f90df2bfca6717cd1df0414d6c3a (3c7e1266) Text, 2.53 KB

T8b949e/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.common.util

Tff7b72import T7ee787co.touchlab.kermit.Logger

Tff7b72object T56d364Exceptions Tb4b4b4{
T8b949e/** Set by the application to provide a custom crash reporting implementation. */
Tff7b72var Te6edf3reporterTb4b4b4: Tb4b4b4(Tb4b4b4(Te6edf3ThrowableTb4b4b4, Tffa657String?Tb4b4b4, Tffa657String?Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4)Tff7b72? Tff7b72= Tff7b72null

T8b949e/**
* Report an exception to the configured reporter (if any) after logging it.
*
* @param exception The exception to report.
* @param tag An optional tag for the report.
* @param message An optional message providing context.
*/
Tff7b72fun Td2a8ffreportTb4b4b4(Te6edf3exceptionTb4b4b4: Te6edf3ThrowableTb4b4b4, Te6edf3tagTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4, Te6edf3messageTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
T8b949e// Log locally first
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3exceptionTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffExceptions.report: Tffd700${Te6edf3tag Tff7b72?: Ta5d6ff"Te6edf3noTff7b72-Te6edf3tagTa5d6ff"Tffd700}Ta5d6ff Tffd700${Te6edf3message Tff7b72?: Ta5d6ff"Te6edf3noTff7b72-Te6edf3messageTa5d6ff"Tffd700}Ta5d6ff" Tb4b4b4}
Te6edf3reporterTff7b72?.Te6edf3invokeTb4b4b4(Te6edf3exceptionTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3messageTb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/** Wraps and discards exceptions, optionally logging them. */
Tff7b72fun Td2a8ffignoreExceptionTb4b4b4(Te6edf3silentTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4, Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3exTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3silentTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffIgnoring exceptionTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

T8b949e/** Suspend-compatible variant of [ignoreException]. */
Tff7b72suspend Tff7b72fun Td2a8ffignoreExceptionSuspendTb4b4b4(Te6edf3silentTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4, Te6edf3innerTb4b4b4: Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3exTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3silentTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffIgnoring exceptionTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Wraps and discards exceptions, but reports them to the crash reporter before logging. Use this for operations that
* should not crash the process but are still unexpected.
*/
Tff7b72fun Td2a8ffexceptionReporterTb4b4b4(Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3exTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3ExceptionsTb4b4b4.Te6edf3reportTb4b4b4(Te6edf3exTb4b4b4, Ta5d6ff"Ta5d6ffexceptionReporterTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffUncaught ExceptionTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.1s